package com.infonautics.dao.imp;

import java.util.List;
import com.hibernate.HibernateDao;
import com.hibernate.Personalinfo;
import com.infonautics.dao.IPersonalinfoDao;
import com.infonautics.page.PageBean;
import com.system.dao.ISystemDao;

public class IPersonalinfoDaoImp implements ISystemDao<Personalinfo>,IPersonalinfoDao{

	HibernateDao<Personalinfo> perinfoDao = new HibernateDao<Personalinfo>();
	
	@Override
	public PageBean<Personalinfo> doList(int pageSize, int page,
			int id) throws Exception {
		return null;
	}

	@Override
	public void doAdd(Personalinfo object) throws Exception {
		if(object != null){
			perinfoDao.addObject(object);
		}
	}

	@Override
	public void doModfiy(Personalinfo object) throws Exception {
		if(object != null){
			perinfoDao.updateObject(object);
		}
	}

	@Override
	public void doDelete(int id) throws Exception {
		perinfoDao.deleteObject(id, Personalinfo.class);
		
	}

	@Override
	public Personalinfo doOne(int id) throws Exception {
		return perinfoDao.getObject(id, Personalinfo.class);
	}

	@Override
	public PageBean<Personalinfo> doPersonalinfoList(int pageSize, int page)
			throws Exception {
		final String hql = "from Personalinfo order by id desc";
		int allRow = perinfoDao.getAllRowCount("select count(*) from Personalinfo");
		int totalPage = PageBean.countTotalPage(pageSize, allRow);
		final int offset = PageBean.countOffset(pageSize, page);
		final int length = pageSize;
		final int currentPage = PageBean.countCurrentPage(page);
		List<Personalinfo> list = perinfoDao.getObjects(hql, offset,length);
	
		PageBean<Personalinfo> pageBean = new PageBean<Personalinfo>();
		pageBean.setPageSize(pageSize);
		pageBean.setCurrentPage(currentPage);
		pageBean.setAllRow(allRow);
		pageBean.setTotalPage(totalPage);
		pageBean.setList(list);
		pageBean.init();
		return pageBean;
	}

	@Override
	public PageBean<Personalinfo> doQueryList(int pageSize, int page, String sql)
			throws Exception {
		final String hql = "from Personalinfo  where 1=1 "+sql+" order by id desc";
		int allRow = perinfoDao.getAllRowCount("select count(*) from Personalinfo where 1=1 "+sql);
		int totalPage = PageBean.countTotalPage(pageSize, allRow);
		final int offset = PageBean.countOffset(pageSize, page);
		final int length = pageSize;
		final int currentPage = PageBean.countCurrentPage(page);
		List<Personalinfo> list = perinfoDao.getObjects(hql, offset,length);
	
		PageBean<Personalinfo> pageBean = new PageBean<Personalinfo>();
		pageBean.setPageSize(pageSize);
		pageBean.setCurrentPage(currentPage);
		pageBean.setAllRow(allRow);
		pageBean.setTotalPage(totalPage);
		pageBean.setList(list);
		pageBean.init();
		return pageBean;
	}

}
